import 'package:flutter/material.dart';
import 'package:x3_component_core/components/button_components/base_button.dart';
import 'package:x3_component_core/components/button_components/base_light_outline_button.dart';
import 'package:x3_component_core/x3_component_core.dart';

/// author：william on 2021/3/24 09:32
/// email：362661044@qq.com
/// 选择中 底部 合计栏
class BaseSelectorFooterStateBar extends StatelessWidget {
  final Stream<int> stream;
  final int initialData;
  final bool showCancel;
  final VoidCallback onSure;

  const BaseSelectorFooterStateBar({Key key, @required this.stream, this.initialData = 0, this.onSure, this.showCancel = false}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return StreamBuilder<int>(
        initialData: initialData,
        stream: stream,
        builder: (context, snapshot) {
          int num = snapshot.data;
          return Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              _buildTextWidget(context, num),
              Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  if (showCancel) _buildCancelBtn(context),
                  if (showCancel) SizedBox(width: 12),
                  BaseButton.four(text: '确定', fill: true, onPress: this.onSure, height: 40, isBottom: true),
                ],
              ),
            ],
          );
        });
  }

  Widget _buildTextWidget(BuildContext context, int num) {
    TextStyle style = Theme.of(context).textTheme.bodyText2;
    TextStyle redStyle = Theme.of(context).textTheme.bodyText2.copyWith(color: Theme.of(context).toggleableActiveColor);
    return BaseComponentUtils.buildTextSpanWidget(['已选择:', num.toString()], styles: {0: style, 1: redStyle});
  }

  Widget _buildCancelBtn(BuildContext context) {
    return BaseButton.four(text: '取消', onPress: () => {Navigator.pop(context)}, height: 40, circular: 4);
  }
}
